package com.guofen.controller.sjq;

import com.guofen.pojo.SjqSolidliquidProduceElectricity;
import com.guofen.pojo.SjqSolidliquidProduceFlatmaterial;
import com.guofen.service.sjq.SjqSolidliquidProduceFlatmaterialService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "SjqSolidliquidProduceFlatmaterialController",description = "固液分离生产现场出渣记录表")
public class SjqSolidliquidProduceFlatmaterialController {
    @Resource
    private SjqSolidliquidProduceFlatmaterialService solidliquidProduceFlatmaterialService;

    @ApiOperation("添加固液分离生产现场出渣记录")
    @PostMapping("/sjq/solidliquidProduceFlatmaterial/add")
    public Result add(@RequestParam("date") String date,@RequestParam("updateTime") String updateTime,@RequestParam("sandOutput") String sandOutputstr,
                      @RequestParam("operator") String operator,@RequestParam(value = "remarks1",required = false) String remarks1){
        Double sandOutput = Double.parseDouble(sandOutputstr);
        if (solidliquidProduceFlatmaterialService.addForm(date,updateTime,sandOutput,operator,remarks1)){
            return ResultGenerator.genSuccessResult();
        }else {
            return ResultGenerator.genFailResult("保存失败");
        }
    }
    @ApiOperation("获取最新一条记录")
    @GetMapping("/sjq/solidliquidProduceFlatmaterial/getlast")
    public Result getlast(){
        return ResultGenerator.genSuccessResult(solidliquidProduceFlatmaterialService.findForm());
    }
    @ApiOperation("为最新记录添加检查人")
    @PostMapping("/sjq/solidliquidProduceFlatmaterial/update")
    public Result update(@RequestParam("inspector") String inspector,@RequestParam(value = "remarks2",required = false) String remarks2){
        if (solidliquidProduceFlatmaterialService.update(inspector, remarks2)){
            return ResultGenerator.genSuccessResult();
        }else {
            return ResultGenerator.genFailResult("检查人已存在");
        }
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/sjq/solidliquidProduceFlatmaterial/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(solidliquidProduceFlatmaterialService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/sjq/solidliquidProduceFlatmaterial/update_record",method = RequestMethod.POST)
    @ResponseBody
    public Result update_record(@ApiParam(name="id",value="id",required=true) @RequestParam(required = true) Integer id,
                         @ApiParam(name="update_time",value="update_time",required=false) @RequestParam(required = false) String update_time,
                         @ApiParam(name="date",value="date",required=false) @RequestParam(required = false) String date,
                         @ApiParam(name="sand_output",value="sand_output",required=false) @RequestParam(required = false) Double sand_output,
                         @ApiParam(name="operator",value="operator",required=false) @RequestParam(required = false) String operator,
                         @ApiParam(name="inspector",value="inspector",required=false) @RequestParam(required = false) String inspector,
                         @ApiParam(name="remarks1",value="remarks1",required=false) @RequestParam(required = false) String remarks1,
                         @ApiParam(name="remarks2",value="remarks2",required=false) @RequestParam(required = false) String remarks2
    ) {
        SjqSolidliquidProduceFlatmaterial record = new SjqSolidliquidProduceFlatmaterial();
        record.setId(id);
        record.setUpdateTime(update_time);
        record.setDate(date);
        record.setSandOutput(sand_output);
        record.setOperator(operator);
        record.setInspector(inspector);
        record.setRemarks1(remarks1);
        record.setRemarks2(remarks2);

        return ResultGenerator.genSuccessResult(solidliquidProduceFlatmaterialService.update_record(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/sjq/solidliquidProduceFlatmaterial/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间(时间戳：毫秒)",required = false) @RequestParam(required = false) Long startTime,
                         @ApiParam(name="endTime",value="截止时间(时间戳：毫秒)", required = false) @RequestParam(required = false) Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(solidliquidProduceFlatmaterialService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(solidliquidProduceFlatmaterialService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
